#!/bin/bash

# 任何命令出错就退出脚本
set -e

# 检查 pip 是否已安装
if ! command -v pip &> /dev/null
then
    echo "pip could not be found, please install it first."
    exit 1
fi

# 安装 Python 包
pip install transformers tqdm scikit-learn datasets seqeval

# warnings 和 importlib 是 Python 内置库，不需要单独安装
# typing 在 Python 3.5+ 是内置库，在此版本以下才需要安装
python_version=$(python --version 2>&1 | awk '{print $2}')
python_major_version=$(echo "${python_version}" | cut -d. -f1)
python_minor_version=$(echo "${python_version}" | cut -d. -f2)

if [[ "$python_major_version" -lt 3 ]] || { [[ "$python_major_version" -eq 3 ]] && [[ "$python_minor_version" -lt 5 ]]; }; then
    pip install typing
else
    echo "typing module is not required for Python $python_major_version.$python_minor_version as it is a built-in library"
fi

echo "All specified packages have been installed successfully."
